package helper.base.string

object ReplaceHelper {
    fun String.replaceLastOccurrence(target: String, replacement: String): String {
        val index = this.lastIndexOf(target)
        return if (index == -1) {
            this // 如果找不到目标子字符串，直接返回原字符串
        } else {
            this.substring(0, index) + replacement + this.substring(index + target.length)
        }
    }
}